package org.hhgzs.modules.erp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.hhgzs.modules.erp.entity.MaterialExtend;
import org.hhgzs.modules.erp.exception.JshException;
import org.hhgzs.modules.erp.mapper.MaterialExtendMapper;
import org.hhgzs.modules.erp.service.MaterialExtendService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.hhgzs.modules.erp.vo.MaterialExtendVo4List;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 产品价格扩展 服务实现类
 * </p>
 *
 * @author peiqy
 * @since 2021-07-14
 */
@Service
@Slf4j
@RequiredArgsConstructor
public class MaterialExtendServiceImpl extends ServiceImpl<MaterialExtendMapper, MaterialExtend> implements MaterialExtendService {

    private final MaterialExtendMapper materialExtendMapper;
    @Override
    public int checkIsBarCodeExist(Long id, String barCode) {

        QueryWrapper<MaterialExtend> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(MaterialExtend::getBarCode,barCode);
        if (id > 0) {
            queryWrapper.lambda().ne(MaterialExtend::getId,id);
        }
        List<MaterialExtend> list =null;
        try{
            list=  list(queryWrapper);
        }catch(Exception e){
            JshException.readFail(log, e);
        }
        return list==null?0:list.size();
    }

    @Override
    public List<MaterialExtendVo4List> getDetailList(Long materialId) {
        List<MaterialExtendVo4List> list=null;
        try{
            list = materialExtendMapper.getDetailList(materialId);
        }catch(Exception e){
            JshException.readFail(log, e);
        }
        return list;
    }
}
